package com.utcs.modules.resource.basic.controller;

import com.utcs.modules.resource.basic.entity.Role;
import com.utcs.modules.resource.basic.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * Created by Fly on 2017/6/1.
 */
@Controller
@RequestMapping(value = "/resource/basic/role/")
public class RoleController {

    @Autowired
    RoleService roleService;

    @ModelAttribute("role")
    public Role get(@RequestParam(required=false) Integer id) {
        if (id!=null){
            return roleService.get(id);
        }else{
            return new Role();
        }
    }

    @RequestMapping(value = {"list",""})
    public String list(Role role, Model model){
        List<Role> roleList = roleService.findAllRole();
        model.addAttribute("list",roleList);
        return "modules/resource/basic/role";
    }

}
